<%@page import="model.Product"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Edit Product Admin</title>
</head>
<body>
	<div class="master-wrapper-content">
		<jsp:include page="heading.jsp"></jsp:include>
		<%
		System.out.println(session.getAttribute("roleId"));
		if(session.getAttribute("roleId") == null || String.valueOf(session.getAttribute("roleId")).equalsIgnoreCase("2")) {
			%>
		<h3 style="color: red">Không đủ quyền để truy cập</h3>
		<%
		}
		else {
		%>
		<jsp:include page="CategoryAdmin.jsp"></jsp:include>
		<div class="container-right">
				<%
					Product product = dataManager.getProductById(Integer.valueOf(request.getParameter("productId")));
				%>

				<form method="post" action="UpdateProduct"
					enctype="multipart/form-data">
					<input type="hidden" name="productId"
						value="<%=product.getProductId() %>" />
					<table>
						<tr>
							<td>Product Name :</td>
							<td><input type="text" name="productName"
								value="<%=product.getProductName() %>" /></td>
						</tr>
						<tr>
							<td><img
								src="<%="/ECommerce/DisplayImage?path=" + product.getImage() %>"
								style="width: 40px; height: 30px;" />
							</td>
							<td><input type="file" name="productImage" /></td>
						</tr>
						<tr>
							<td>Description :</td>
							<td><textarea rows="5" cols="20" name="description"><%=product.getDescription() %></textarea>
							</td>
						</tr>
						<tr>
							<td>Price :</td>
							<td><input type="text" name="price"
								value="<%=product.getPrice() %>" /></td>
						</tr>
						<tr>
							<td>Quantity</td>
							<td><input type="text" name="quantity"
								value="<%=product.getQuantity() %>" /></td>
						</tr>
						<tr>
							<td>Producer :</td>
							<td>
							<%
								ProducerOwnCategory poc = dataManager.getProducerOwnCategory(product.getProducterOwnCategory());
								List<Producer> producers = dataManager.getAllProducer();
								List<Category> categorys = dataManager.getAllCategory();
							%> 
							<select name="producerId">
							<%
							for(Producer producer : producers) {
								if(producer.getProducerId() == poc.getProducerId()) {
									%>
										<option value="<%=producer.getProducerId() %>"
											selected="selected"><%=producer.getProducerName() %></option>
									<%
								}
							else {
								%>
									<option value="<%=producer.getProducerId() %>"><%=producer.getProducerName() %></option>
									<%
							}
						}
					%>
							</select>
							</td>
						</tr>
						<tr>
							<td>Category :</td>
							<td><select name="categoryId">
									<%
						for(Category category : categorys) {
							if(category.getCategoryId() == poc.getProducerId()) {
								%>
									<option value="<%=category.getCategoryId() %>"
										selected="selected">
										<%=category.getCategoryName() %></option>
									<%
							}
							else {
								%>
									<option value="<%=category.getCategoryId() %>"><%=category.getCategoryName() %></option>
									<%
							}
						}
					%>
							</select>
							</td>
						</tr>
					</table>
					<br /> <input type="submit" value="Edit Product" />
				</form>
		</div>
		<div class="clear"></div>
		<%
		}
		%>
	</div>
	
</body>
</html>